home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / prpas.zip / SAMPLE.PAS < prev   
Pascal/Delphi Source File  |  1993-04-14  |  2KB  |  77 lines

  1. PROGRAM Sample;
  2. uses crt;
  3.  
  4. (* This is a Turbo Pascal program for testing PrettyPascal 1.0
  5. *  The program simply writes a..y diagonally on the screen 6 times
  6. *)
  7.  
  8. TYPE
  9.   str26= string[26];
  10.  
  11. var
  12.   m: Integer;
  13.  
  14. CONST
  15.   str: str26 = 'abcdefghijklmnopqrstuvwxyz';
  16.  
  17.  
  18.   Procedure display(m: integer; s: str26);
  19.  
  20.   (* Pre-cond : 0<=m<3 && s = string of alphabet
  21.   *  Post-cond: string s written diagonally twice
  22.   *)
  23.  
  24.   var r, c: integer;
  25.  
  26.   begin
  27.                    (* demonstrate "if" constructs *)
  28.     if m = 0 then            { check value of m }
  29.      c := 0
  30.   ELSE IF m = 1 then
  31.     c := 10
  32.   else
  33.       c := 20;(* c = 0, 10 or 20 depending on m *)
  34.  
  35.                  { demonstrates "for" constructs }
  36.   FOR r:=0 to 25 DO
  37.    BEGIN
  38.          gotoxy(r,c);
  39.       write(s[r]);    (* keep looping until r=25 *)
  40.     c:= c + 1;
  41.   END;
  42.  
  43.   { another demonstration of "if" construct }
  44.   if m=0 then begin 
  45.        c := 5;
  46.     end
  47.   else if m=1 then
  48.     BEGIN
  49.        c := 15;
  50.     END
  51.   else
  52.   begin
  53.         c := 25;
  54.   end;    (* c = 5, 15 or 25 depending on m *)
  55.  
  56. { demonstrates "while" construct }
  57.   r := 0;
  58.   WHILE r <> 25 do begin          (* loop until r=25 *)
  59.         gotoxy(r,c);   (* position cursor for display *)
  60.      write(s[r]);  (* print character *)
  61.       r:= r + 1;
  62.       c:= c + 1;
  63.      END
  64.   end;   
  65.  
  66.  
  67. BEGIN
  68.              (* loop invariant P0 == 0<=m<3 and alphabet written m*2 times thus far *)
  69.     m:=0;   { P0 true }
  70.     ClrScr;
  71.   while m <> 3 do
  72.     begin 
  73.     display ( m, str );   (* call display for writing str *)
  74.     m:=m + 1;(* add 1 to m => P0 true *)
  75.    END  (* finished WITH loop end. *)
  76. END.
  77.